package com.mine.distinctionteam.ui.businessman.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mine.distinctionteam.R;
import com.mine.distinctionteam.bean.businessman.GoodsListBeans;

import java.util.List;


/**
 *
 */
public class BusinessmanGridAdapter extends BaseAdapter{
    public Context mContext;
    public List<GoodsListBeans> list;
    public LayoutInflater inflater;

    public BusinessmanGridAdapter(Context mContext, List<GoodsListBeans> list) {
        this.mContext=mContext;
        this.list=list;
        inflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.item_gridview_unused,parent,false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(list.get(position).getCover()).into(viewHolder.imageView);
        viewHolder.textView_name.setText(list.get(position).getBrandName());
        viewHolder.textView_goodsname.setText(list.get(position).getGoodsName());
        viewHolder.textView_price.setText("￥"+list.get(position).getSellPrice());
        viewHolder.textView_oldprice.setText("￥"+list.get(position).getOriginalPrice());
        viewHolder.textView_oldprice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
        TextView textView_name;
        TextView textView_goodsname;
        TextView textView_price;
        TextView textView_oldprice;

        public ViewHolder(View view) {
            imageView = (ImageView) view.findViewById(R.id.imageview_gridview_unused);
            textView_name= (TextView) view.findViewById(R.id.textview_gridview_unused_name);
            textView_goodsname= (TextView) view.findViewById(R.id.textview_gridview_unused_goodsname);
            textView_price= (TextView) view.findViewById(R.id.textview_gridview_unused_price);
            textView_oldprice= (TextView) view.findViewById(R.id.textview_gridview_unused_oldprice);
        }
    }

    //刷新数据
    public void reload(List<GoodsListBeans> _list, boolean isClear) {
        if (isClear) {
            list.clear();
        }
        list.addAll(_list);
        notifyDataSetChanged();
    }
}
